#include "AMFMessage.h"
#include "AMFWriter.h"
#include "AMFReader.h"
//#include <wx/log.h>
namespace AMF {

AMFMessage::AMFMessage()
{
    //ctor
//    wxLogMessage(_("建立AMFMessage"));
}

AMFMessage::~AMFMessage()
{
//    wxLogMessage(_("釋放AMFMessage"));
    _headers.clear();
    for(unsigned int i = 0; i < _bodies.size();i++) if(_bodies[i] != NULL)delete _bodies[i];
    _bodies.clear();
}

void AMFMessage::Clear()
{
    _headers.clear();
    _bodies.clear();
}

void AMFMessage::Serializer(wxOutputStream *output)
{
    AMFWriter(output).WriteAMFMessage(this);
}

AMFMessage AMFMessage::Deserializer(wxInputStream &input)
{
    AMFReader reader(input);
    return reader.ReadAMFMessage();
}

wxString AMFMessage::toString(bool writeType)
{
    wxString tmp;
    tmp += _("Version:");
    tmp += (_version == AMF0?_("AMF0"):_("AMF3"));
    tmp += wxString::Format(_("\r\nBody Count:%d"), _bodies.size());
    tmp += _("\r\n");
    for (unsigned int i = 0; i < _bodies.size(); i++)
    {
        tmp += wxString::Format(_("Body(%d):\r\n"), i);
        tmp += writeType?_bodies[i]->ToTypeString():_bodies[i]->ToString();
        tmp += _("========================================\r\n");
    }
    return tmp;
}

} // namespace AMF
